package cn.tedu.ivoswork.dict.controller;

import cn.tedu.ivoswork.base.response.JsonResult;
import cn.tedu.ivoswork.dict.pojo.dto.DictQuery;
import cn.tedu.ivoswork.dict.pojo.dto.SaveDictFormParam;
import cn.tedu.ivoswork.dict.pojo.vo.DictVO;
import cn.tedu.ivoswork.dict.service.IDictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/dict")
public class DictController {
    @Autowired
    IDictService dictService;

    @GetMapping("select")
    public JsonResult select(DictQuery dictQuery){
        log.debug("查询字典：参数={}",dictQuery);
        List<DictVO> list = dictService.select(dictQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult save (SaveDictFormParam saveDictFormParam){
        log.debug("保存字典：参数={}",saveDictFormParam);
        dictService.save(saveDictFormParam);
        return JsonResult.ok();
    }

    @PostMapping("delete")
    public JsonResult delete (Long id){
        log.debug("删除字典：参数={}",id);
        dictService.delete(id);
        return JsonResult.ok();
    }
}
